Programmatically running an analyzer
Using the SDK, it is possible to invoke analyzers programmatically.
This can be done via the Client type.
The Client
needs to know what type of analyzer you intend to load: console or editor.
open FSharp.Analyzers.SDK
let client = Client<CliAnalyzerAttribute, CliContext>()
let countLoaded = client.LoadAnalyzers @"C:\MyAnalyzers"
let ctx = Unchecked.defaultof<CliContext> // Construct your context...
client.RunAnalyzers(ctx)
Multiple items
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp.Analyzers
namespace FSharp.Analyzers.SDK
val client: Client<CliAnalyzerAttribute,CliContext>
Multiple items
type Client<'TAttribute,'TContext (requires 'TAttribute :> AnalyzerAttribute and 'TContext :> Context)> = new: logger: ILogger -> Client<'TAttribute,'TContext> + 1 overload member LoadAnalyzers: dir: string * ?excludeInclude: ExcludeInclude -> AssemblyLoadStats member RunAnalyzers: ctx: 'TContext -> Async<AnalyzerMessage list> member RunAnalyzersSafely: ctx: 'TContext -> Async<AnalysisResult list>
--------------------
new: unit -> Client<'TAttribute,'TContext>
new: logger: Extensions.Logging.ILogger -> Client<'TAttribute,'TContext>
type Client<'TAttribute,'TContext (requires 'TAttribute :> AnalyzerAttribute and 'TContext :> Context)> = new: logger: ILogger -> Client<'TAttribute,'TContext> + 1 overload member LoadAnalyzers: dir: string * ?excludeInclude: ExcludeInclude -> AssemblyLoadStats member RunAnalyzers: ctx: 'TContext -> Async<AnalyzerMessage list> member RunAnalyzersSafely: ctx: 'TContext -> Async<AnalysisResult list>
--------------------
new: unit -> Client<'TAttribute,'TContext>
new: logger: Extensions.Logging.ILogger -> Client<'TAttribute,'TContext>
Multiple items
type CliAnalyzerAttribute = inherit AnalyzerAttribute new: [<Optional; DefaultParameterValue (("Analyzer" :> obj))>] name: string * [<Optional; DefaultParameterValue (("" :> obj))>] shortDescription: string * [<Optional; DefaultParameterValue (("" :> obj))>] helpUri: string -> CliAnalyzerAttribute member Name: string
<summary> Marks an analyzer for scanning during the console application run. </summary>
--------------------
new: [<System.Runtime.InteropServices.Optional; System.Runtime.InteropServices.DefaultParameterValue (("Analyzer" :> obj))>] name: string * [<System.Runtime.InteropServices.Optional; System.Runtime.InteropServices.DefaultParameterValue (("" :> obj))>] shortDescription: string * [<System.Runtime.InteropServices.Optional; System.Runtime.InteropServices.DefaultParameterValue (("" :> obj))>] helpUri: string -> CliAnalyzerAttribute
type CliAnalyzerAttribute = inherit AnalyzerAttribute new: [<Optional; DefaultParameterValue (("Analyzer" :> obj))>] name: string * [<Optional; DefaultParameterValue (("" :> obj))>] shortDescription: string * [<Optional; DefaultParameterValue (("" :> obj))>] helpUri: string -> CliAnalyzerAttribute member Name: string
<summary> Marks an analyzer for scanning during the console application run. </summary>
--------------------
new: [<System.Runtime.InteropServices.Optional; System.Runtime.InteropServices.DefaultParameterValue (("Analyzer" :> obj))>] name: string * [<System.Runtime.InteropServices.Optional; System.Runtime.InteropServices.DefaultParameterValue (("" :> obj))>] shortDescription: string * [<System.Runtime.InteropServices.Optional; System.Runtime.InteropServices.DefaultParameterValue (("" :> obj))>] helpUri: string -> CliAnalyzerAttribute
type CliContext =
{
FileName: string
SourceText: ISourceText
ParseFileResults: FSharpParseFileResults
CheckFileResults: FSharpCheckFileResults
TypedTree: FSharpImplementationFileContents option
CheckProjectResults: FSharpCheckProjectResults
}
interface Context
member Equals: CliContext * IEqualityComparer -> bool
member GetAllEntities: publicOnly: bool -> AssemblySymbol list
member GetAllSymbolUsesOfFile: unit -> FSharpSymbolUse seq
member GetAllSymbolUsesOfProject: unit -> FSharpSymbolUse array
<summary> All the relevant compiler information for a given file. Contains the source text, untyped and typed tree information. </summary>
<summary> All the relevant compiler information for a given file. Contains the source text, untyped and typed tree information. </summary>
val countLoaded: AssemblyLoadStats
member Client.LoadAnalyzers: dir: string * ?excludeInclude: ExcludeInclude -> AssemblyLoadStats
val ctx: CliContext
module Unchecked
from Microsoft.FSharp.Core.Operators
val defaultof<'T> : 'T
member Client.RunAnalyzers: ctx: 'TContext -> Async<AnalyzerMessage list>